const express = require('express');
const router = express.Router();
const db = require('../db/mysqlConfig');

// 获取所有台球室 / 按地址搜索
router.get('/api/billiard_rooms', (req, res) => {
    const { location } = req.query;

    let sql = 'SELECT * FROM billiard_rooms';
    let params = [];

    if (location) {
        sql += ' WHERE location LIKE ?';
        params.push(`%${location}%`);
    }

    db.query(sql, params, (error, results) => {
        if (error) {
            return res.status(500).json({ code: 1, message: '查询失败', error });
        }
        res.json({ code: 0, data: results });
    });
});

module.exports = router;
